import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { resolve } from 'path';
import { loadEnv } from './src/utils/viteBuild'
import viteSvgIcons from 'vite-plugin-svg-icons';
const pathResolve = (dir: string): any => {
	return resolve(__dirname, '.', dir);
};
const { VITE_PORT, VITE_OPEN, VITE_PUBLIC_PATH } = loadEnv();

const alias: Record<string, string> = {
	'@': pathResolve('src/')
};

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    viteSvgIcons({
      // 配置路劲在你的src里的svg存放文件
      iconDirs: [pathResolve('src/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
  ],
	root: process.cwd(),
  resolve: { alias },
  base: process.env.NODE_ENV === 'production' ? VITE_PUBLIC_PATH : './',
  server: {
    port: VITE_PORT,
    // 是否自动在浏览器打开
    open: VITE_OPEN,
    // 是否开启 https
    https: false,
    // proxy: {
    //   '/api': {
    //     target: 'http://localhost:8081',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, ''),
    //   },
    // },
  },
  build: {
		outDir: 'dist',
		minify: 'esbuild',
		sourcemap: false,
	}
})
